import {Injectable} from "injection-js";
import {Mut, VueService} from "vue3-oop";
import UserApi from "../..//UserApi";


@Injectable()
export default class ValidPrmsSercice extends VueService {

  constructor(

  ){
    super();
  }

  @Mut() state = {
    userId:"",
    personname:""
  }

  init=(userId:string,personname:string)=>{
    this.state.userId = userId;
    this.state.personname = personname;
    this.searchData("");
  }

  @Mut() pagination={
    showSizePicker: true,
    showQuickJumper: true,
    pageSizes: [10,20,50,100],
    pageSize: 10,
    page: 1,
    itemCount: 0,
  }

  /**
   * 查询所有分配给用户的权限
   * @param value 快速搜索框输入值
   */
  searchData=(value:string)=>{
    if(this.state.userId.length>0){
      UserApi.prmsAllocated({
        params:{
          userId: this.state.userId
        },
        page:{size: this.pagination.pageSize, current: this.pagination.page}
      }).then(({data})=>{
        if(data.success&&data.record){
          this.panelProps.nDataTableProps.data = data.record
        }
      })
    }
  }

  @Mut() panelProps = {
    name: "权限列表",
    code: "prms_list",
    default: false,
    showSearchBar: true,
    showSearchExt: true,
    toolbarActions: [{
      name: "测试C", needCheck: false, inMore: true, onClick: () => {
      }
    }],
    onQuickSearch: this.searchData,
    nDataTableProps: {
      columns: [
        {
          key: "priority",
          title: "优先级"
        },{
          key: "prmsName",
          title: "权限名称"
        },{
          key: "prmsCode",
          title: "权限编码"
        },{
          key: "type",
          title: "类型"
        },{
          key: "disabled",
          title: "禁用",
          render: (row:any)=>(row['disabled']===1?"是":"否")
        },{
          key: "roleName",
          title: "角色名称"
        },{
          key: "roleCode",
          title: "角色编码"
        },{
          key: "remark",
          title: "备注"
        }
      ],
      data: [],
      pagination: this.pagination
    },
    onMounted:()=>{
      this.searchData("")
    }
  }

}